package controller.expertInfo.checkNotEnough;

import base.response.OffsetLimitPage;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import response.CommonResult;
import services.specific.CheckNotEnoughServices;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/12/2.
 */
@Controller


@RequestMapping("expertInfo/checkNotEnough")
public class CheckNotEnoughController {

    @Autowired
    CheckNotEnoughServices checkNotEnoughServices;


    @RequiresPermissions("expertInfo:checkNotEnough:default")
    @RequestMapping("index")
    public String index(Integer years,Map map) throws Exception {
        map.put("years",years);
        return "expertInfo/checkNotEnough/index";
    }



    @RequiresPermissions("expertInfo:checkNotEnough:default")
    @ResponseBody
    @RequestMapping("select")
    public OffsetLimitPage select(Integer years, String itemId,Integer offset,Integer limit) throws Exception {
        if (years==null){
            years=1;
        }
        return checkNotEnoughServices.select(years*2,itemId,years,offset,limit);
    }



    @RequiresPermissions("expertInfo:checkNotEnough:default")
    @ResponseBody
    @RequestMapping("welcomeTips")
    public CommonResult welcomeTips() throws Exception {
        CommonResult commonResult=new CommonResult();
        for (int i = 1;i  < 4; i++) {
            OffsetLimitPage  offsetLimitPage=  select(i,null,0,1);
            if (offsetLimitPage.getTotal()!=0){
                Map dataMap = new HashMap();
                dataMap.put("info",offsetLimitPage.getTotal()+"位专家" +i+"年核查次数小于"+i*2+"次");
                dataMap.put("url","expertInfo/checkNotEnough/index?years="+i);
                commonResult.setData(dataMap);
                return  commonResult.setSuccess();
            }
        }
        return  commonResult.setError();
    }


}
